function [stageSum] = resultView(data,xScale)
if nargin < 2
  xScale = 'sec'
end
if strcmp(xScale,'min')
    data(:,1) = data(:,1)/60;
end
if strcmp(xScale,'hour')
    data(:,1) = data(:,1)/60/60;
end
fprintf('showing stages over %.3f %s of sleep\n',max(data(:,1)),xScale)
stages = data(:,2);
%figure;
hold on;

ylim([0,6])
set(gca,'YTick',0:5);
grid on;
%ax.YTick = [0:5];
xlabel(strcat('Time [',xScale,']'))
ylabel('Stage')

stageSum = zeros(6,1);
%plot(data(:,1),data(:,2),'o')
for i=0:5
    idx = find(stages == i);
    stageSum(i+1) = sum(idx);
    st1 = data(idx,:);
    if i == 0;    plot(st1(:,1),st1(:,2),'ob'); end;
    if i == 1;    plot(st1(:,1),st1(:,2),'or'); end;
    if i == 2;    plot(st1(:,1),st1(:,2),'og'); end;
    if i == 3;    plot(st1(:,1),st1(:,2),'om'); end;
    if i == 5;    plot(st1(:,1),st1(:,2),'ok'); end;
end
hold off;
end